home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / LIB / GLUT / win32_util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  3.2 KB  |  115 lines

  1.  
  2. /* Copyright (c) Nate Robins, 1997. */
  3.  
  4. /* portions Copyright (c) Mark Kilgard, 1997, 1998. */
  5.  
  6. /* This program is freely distributable without licensing fees 
  7.    and is provided without guarantee or warrantee expressed or 
  8.    implied. This program is -not- in the public domain. */
  9.  
  10.  
  11. #include "glutint.h"
  12. #include "glutstroke.h"
  13. #include "glutbitmap.h"
  14. #if defined(__CYGWIN32__)
  15. typedef MINMAXINFO* LPMINMAXINFO;
  16. #else
  17. #include <sys/timeb.h>
  18. #endif
  19.  
  20. extern StrokeFontRec glutStrokeRoman, glutStrokeMonoRoman;
  21. extern BitmapFontRec glutBitmap8By13, glutBitmap9By15, glutBitmapTimesRoman10, glutBitmapTimesRoman24, glutBitmapHelvetica10, glutBitmapHelvetica12, glutBitmapHelvetica18;
  22.  
  23. int
  24. gettimeofday(struct timeval* tp, void* tzp)
  25. {
  26.   struct timeb tb;
  27.  
  28.   ftime(&tb);
  29.   tp->tv_sec = tb.time;
  30.   tp->tv_usec = tb.millitm * 1000;
  31.  
  32.   /* 0 indicates that the call succeeded. */
  33.   return 0;
  34. }
  35.  
  36. /* To get around the fact that Microsoft DLLs only allow functions
  37.    to be exported and now data addresses (as Unix DSOs support), the
  38.    GLUT API constants such as GLUT_STROKE_ROMAN have to get passed
  39.    through a case statement to get mapped to the actual data structure
  40.    address. */
  41. void*
  42. __glutFont(void *font)
  43. {
  44.   switch((int)font) {
  45.   case (int)GLUT_STROKE_ROMAN:
  46.     return &glutStrokeRoman;
  47.   case (int)GLUT_STROKE_MONO_ROMAN:
  48.     return &glutStrokeMonoRoman;
  49.   case (int)GLUT_BITMAP_9_BY_15:
  50.     return &glutBitmap9By15;
  51.   case (int)GLUT_BITMAP_8_BY_13:
  52.     return &glutBitmap8By13;
  53.   case (int)GLUT_BITMAP_TIMES_ROMAN_10:
  54.     return &glutBitmapTimesRoman10;
  55.   case (int)GLUT_BITMAP_TIMES_ROMAN_24:
  56.     return &glutBitmapTimesRoman24;
  57.   case (int)GLUT_BITMAP_HELVETICA_10:
  58.     return &glutBitmapHelvetica10;
  59.   case (int)GLUT_BITMAP_HELVETICA_12:
  60.     return &glutBitmapHelvetica12;
  61.   case (int)GLUT_BITMAP_HELVETICA_18:
  62.     return &glutBitmapHelvetica18;
  63.   }
  64.   __glutFatalError("out of memory.");
  65.   /* NOTREACHED */
  66. }
  67.  
  68. int
  69. __glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
  70. {
  71.   /* the transparent pixel on Win32 is always index number 0.  So if
  72.      we put this routine in this file, we can avoid compiling the
  73.      whole of layerutil.c which is where this routine normally comes
  74.      from. */
  75.   return 0;
  76. }
  77.  
  78. void
  79. __glutAdjustCoords(Window parent, int* x, int* y, int* width, int* height)
  80. {
  81.   RECT rect;
  82.  
  83.   /* adjust the window rectangle because Win32 thinks that the x, y,
  84.      width & height are the WHOLE window (including decorations),
  85.      whereas GLUT treats the x, y, width & height as only the CLIENT
  86.      area of the window. */
  87.   rect.left = *x; rect.top = *y;
  88.   rect.right = *x + *width; rect.bottom = *y + *height;
  89.  
  90.   /* must adjust the coordinates according to the correct style
  91.      because depending on the style, there may or may not be
  92.      borders. */
  93.   AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
  94.            (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
  95.            FALSE);
  96.   /* FALSE in the third parameter = window has no menu bar */
  97.  
  98.   /* readjust if the x and y are offscreen */
  99.   if(rect.left < 0) {
  100.     *x = 0;
  101.   } else {
  102.     *x = rect.left;
  103.   }
  104.   
  105.   if(rect.top < 0) {
  106.     *y = 0;
  107.   } else {
  108.     *y = rect.top;
  109.   }
  110.  
  111.   *width = rect.right - rect.left;    /* adjusted width */
  112.   *height = rect.bottom - rect.top;    /* adjusted height */
  113. }
  114.  
  115.